package com.zzyl.nursing.task;

import com.zzyl.nursing.mapper.MemberReservationMapper;
import com.zzyl.nursing.mapper.ReservationMapper;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class ReservationScheduler {

    @Resource
    private MemberReservationMapper memberReservationMapper;

    /**
     * 定时任务：每30分钟执行一次
     * cron 表达式：0 0/30 * * * ?  表示“每小时的 0分、30分执行”
     */
    @Scheduled(cron = "0 0/30 * * * ?")
    public void checkAndUpdateExpiredReservations() {
        int updatedCount = memberReservationMapper.updateExpiredReservations();
        System.out.println("已更新 " + updatedCount + " 条过期预约记录");
    }
}